using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using SapaFinance.Domain.Model;

namespace SapaFinance.Domain.EntityFramework
{
    internal class RequestConfiguration : EntityTypeConfiguration<Request>
    {
        public RequestConfiguration()
        {
            ToTable(typeof (Request).Name.ToLower());
            HasKey(x => x.UID);
            Property(x => x.UID).HasColumnName("id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(x => x.Description).HasColumnName("description").IsOptional();
            Property(x => x.PaymentPeriod).HasColumnName("paymentperiod").IsRequired();
            Property(x => x.PaymentPurpose).HasColumnName("purpose").IsRequired();
            Property(x => x.Unique).HasColumnName("number").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            HasRequired(p => p.CreatedBy).WithMany().Map(m => m.MapKey("createdbyid")).WillCascadeOnDelete(false);
            HasRequired(p => p.ChangedBy).WithMany().Map(m => m.MapKey("changedbyid")).WillCascadeOnDelete(false);
            HasOptional(p => p.DeletedBy).WithOptionalDependent().Map(m => m.MapKey("deletedbyid")).WillCascadeOnDelete(false);
            HasOptional(p => p.AcceptedBy).WithOptionalDependent().Map(m => m.MapKey("acceptedbyid")).WillCascadeOnDelete(false);
            HasRequired(p => p.Payment).WithMany().Map(m => m.MapKey("moneyid")).WillCascadeOnDelete(false);
            HasRequired(a => a.BudgetItem).WithMany().Map(m => m.MapKey("budgetitemid")).WillCascadeOnDelete(false);
            HasRequired(x => x.Payee).WithMany().Map(m => m.MapKey("payeeid")).WillCascadeOnDelete(false);
            HasRequired(x => x.PayeeAccount).WithMany().Map(m => m.MapKey("payeeaccountid")).WillCascadeOnDelete(false);
            HasOptional(x => x.Payer).WithMany().Map(m => m.MapKey("payerid")).WillCascadeOnDelete(false);;
            HasRequired(x => x.Department).WithMany().Map(m => m.MapKey("cfoid")).WillCascadeOnDelete(false);
            HasRequired(p => p.PaymentType).WithMany().Map(m => m.MapKey("paymenttypeid")).WillCascadeOnDelete(false);
        }
    }
}